﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLyQuangCao
{
    public partial class frmGD_QC : Form
    {
        
        public frmGD_QC()
        {
            InitializeComponent();         
        }
        private void frmQuangCao_Load(object sender, EventArgs e)
        {
            prvSetData();
        }
        private DataSet ds = new DataSet();

        private void button1_Click(object sender, EventArgs e)
        {

            frmGD_QC_Edit fQC = new frmGD_QC_Edit();
            fQC.ShowDialog();
            prvSetData();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa không?", "Thông Báo", MessageBoxButtons.YesNo)== DialogResult.Yes) ;
            this.Close();

            {

                string ml = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                try
                {
                    string sql = "delete  from LoaiQuangCao where ma_loai = '" + ml + "'";
                    SqlConnection sc = new SqlConnection(frmChinh.me.sqlcon);
                    SqlCommand sqlCmd = new SqlCommand(sql, sc);
                    sc.Open();
                    sqlCmd.ExecuteNonQuery();
                    sc.Close();
                }
                catch
                {
                    MessageBox.Show("Khong the xoa vi da co du lieu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
            }
        }

        private void txtGiaMotKy_KeyPress(object sender, KeyPressEventArgs e)
        {
            int p = (int)e.KeyChar;
            if (!(((p >= 48) && (p <= 57)) || (p == 8)))
                e.Handled = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            frmGD_QC_Edit fQC_S = new frmGD_QC_Edit();
            fQC_S.pMaLoai = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            fQC_S.pGhiChu = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            fQC_S.pGia = (Int32)dataGridView1.CurrentRow.Cells[2].Value;
            fQC_S.ShowDialog();
            prvSetData();
        }
        private void prvSetData()
        {
            string sql = "select * from LoaiQuangCao";
            frmChinh.me.cn1.laydulieu(sql, frmChinh.me.sqlcon, ds, "loaiquangcao");
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "loaiquangcao";
        }
    }
}
